---
description: "Reference for Nitric's Dart library - Returns a reference to the latest version of a secret, regardless of that version's ID."
---

# Dart - secret.latest()

<Note>
  This is reference documentation for the Nitric Dart SDK. To learn about
  Secrets in Nitric start with the [Secrets docs](/secrets).
</Note>

Returns a reference to the `latest` version of a secret, regardless of that version's ID.

```dart
import 'package:nitric_sdk/nitric.dart';

final keyRef = Nitric.secret("apiKey").allow([
  SecretPermission.access,
]);

final latestVersion = keyRef.latest();
```

## Notes

`latest()` is most useful when you always want the most recent secret values from the secrets manager. Database credentials and API keys are good examples of secrets where the latest value is usually what you want.

For symmetric encryption, you'll need to retrieve the version of the secret used to _encrypt_ a value when you try to _decrypt_ it again. In those cases `latest()` isn't a good choice, use [version()](./secret-version) instead.

## Examples

### Get a reference to the latest secret version

```dart
import 'package:nitric_sdk/nitric.dart';

final keyRef = Nitric.secret("apiKey").allow([
  SecretPermission.access,
]);

final latestVersion = keyRef.latest();
```

### Access the latest value of a secret

```dart
import 'package:nitric_sdk/nitric.dart';

final keyRef = Nitric.secret("apiKey").allow([
  SecretPermission.access,
]);

final key = await keyRef.latest().access();
```

<Note>
  See [secret.version().access()](./secret-version-access) for more details.
</Note>
